Skip to content

feat(lk): lk analytics session list --agent-id filters by cloud agent - #1144

Open
JackNDwyer wants to merge 1 commit into
mainfrom
jackdwyer/analytics-session-agent-filter
Open

JackNDwyer wants to merge 1 commit into
mainfrom
jackdwyer/analytics-session-agent-filter

Conversation

@JackNDwyer

Copy link
Copy Markdown
Contributor

The Public API's ListProjectSessions already filters by the cloud agent that served a session (filter.agentId), but lk analytics session list didn't expose it. A coding agent asked "show me this agent's sessions" had to list everything and filter by guesswork.

  • --agent-id CA_… sends filter.agentId. Like --room and --tag, it requires --user-auth and stays hidden until a user signs in.
  • A value that isn't a CA_ ID fails before any request, with a pointer to lk agent list. The API filters by cloud agent ID, not name, so a name would otherwise return an empty list that looks like "no sessions."

Not in this PR: filtering by agent name. A self-hosted agent has no CA_ ID and the sessions API can't filter by name, so that needs upstream work. Once lk agent list works under --user-auth (#1138), a follow-up could take a name and look up its ID.

Tested with go test ./cmd/lk/ ./pkg/public/, plus new cases for the query param, the flag, the bad-ID error, and the API-key-mode refusal.

🤖 Generated with Claude Code

The Public API's ListProjectSessions already filters by the cloud agent
that served a session (filter.agentId), but the CLI didn't send it, so a
coding agent asked for one agent's sessions had to list every session
and guess.

--agent-id takes a CA_ ID, as lk agent list shows it, and requires
--user-auth like the other filters. A value that isn't a CA_ ID fails
before any request, since the API filters by ID, not agent name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

Comment thread cmd/lk/analytics.go
Statuses: cmd.StringSlice("status"),
RoomPrefix: cmd.String("room"),
Tags: cmd.StringSlice("tag"),
AgentID: cmd.String("agent-id"),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Empty agent flag returns unfiltered sessions

With --agent-id="", sessionListOptions accepts an empty ID. listProjectSessionsParams omits the agent filter, so results can include sessions from other agents.

Learn more

The public client uses an empty AgentID to represent an omitted filter, which is appropriate for its zero-value options. The CLI can distinguish an omitted flag from an explicitly empty flag via cmd.IsSet, as the auth mode validator already does. It currently passes the parsed string alone, so both cases reach listProjectSessionsParams as an absent filter.

Example: An automation script runs lk --user-auth analytics session list --agent-id "$AGENT_ID" --json with an empty AGENT_ID. The command succeeds and returns the project’s session page without restricting it to an agent.

Recommended fix: In sessionListOptions, reject an explicitly set but empty --agent-id before constructing the options. Keep an omitted flag valid and add a command options test for --agent-id=.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant